Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@math.gl/web-mercator
Advanced tools
@math.gl/web-mercator is a JavaScript library that provides utilities for working with Web Mercator projections. It is part of the math.gl suite of libraries and is designed to facilitate geographic calculations and transformations, particularly for mapping and visualization applications.
Project geographic coordinates to Web Mercator
This feature allows you to project geographic coordinates (longitude and latitude) to Web Mercator coordinates. The code sample demonstrates how to create a WebMercatorViewport and project a specific geographic coordinate to Web Mercator coordinates.
const { WebMercatorViewport } = require('@math.gl/web-mercator');
const viewport = new WebMercatorViewport({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
const [x, y] = viewport.project([-122.45, 37.78]);
console.log(`Projected coordinates: (${x}, ${y})`);
Unproject Web Mercator coordinates to geographic coordinates
This feature allows you to unproject Web Mercator coordinates back to geographic coordinates (longitude and latitude). The code sample demonstrates how to create a WebMercatorViewport and unproject a specific Web Mercator coordinate to geographic coordinates.
const { WebMercatorViewport } = require('@math.gl/web-mercator');
const viewport = new WebMercatorViewport({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
const [longitude, latitude] = viewport.unproject([400, 300]);
console.log(`Geographic coordinates: (${longitude}, ${latitude})`);
Calculate the bounding box of a viewport
This feature allows you to calculate the geographic bounding box of a viewport. The code sample demonstrates how to create a WebMercatorViewport and get the bounding box of the viewport.
const { WebMercatorViewport } = require('@math.gl/web-mercator');
const viewport = new WebMercatorViewport({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 12
});
const bounds = viewport.getBounds();
console.log(`Bounding box: ${JSON.stringify(bounds)}`);
Proj4 is a JavaScript library for cartographic projections and coordinate transformations. It supports a wide range of projections and is highly configurable. Compared to @math.gl/web-mercator, proj4 offers more flexibility and a broader range of projections, but it may be more complex to use for simple Web Mercator transformations.
D3-geo is a module of the D3.js library that provides geographic projections and transformations. It is well-integrated with the D3 ecosystem and is suitable for creating complex visualizations. Compared to @math.gl/web-mercator, d3-geo offers more visualization capabilities but may require more setup for basic Web Mercator transformations.
Mapbox GL JS is a JavaScript library for interactive, customizable vector maps on the web. It includes built-in support for Web Mercator projections and provides a rich set of features for map rendering and interaction. Compared to @math.gl/web-mercator, Mapbox GL JS is more focused on map rendering and interaction, while @math.gl/web-mercator is more focused on the mathematical aspects of projections.
math.gl is a suite of math modules for 3D and geospatial applications.
This module contains utilities for perspective-enabled Web Mercator projections.
For documentation please visit the website.
3.6.3
FAQs
Utilities for perspective-enabled Web Mercator projections
The npm package @math.gl/web-mercator receives a total of 240,246 weekly downloads. As such, @math.gl/web-mercator popularity was classified as popular.
We found that @math.gl/web-mercator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.